
<%= turbo_frame_tag dom_id(@order, :line_items), class: "card mb-4 overflow-hidden" do %>
  <% if @line_items.any? %>
    <div class="card-header d-flex justify-content-between align-items-center pb-3">
      <h5 class="card-title d-flex align-items-center">
        <%= Spree.t(:line_items) %>
        <span class="badge badge-info ml-2"><%= @line_items.count %></span>
      </h5>
      <div class="d-flex gap-2">
        <% if can?(:create, Spree::LineItem.new(order: @order)) %>
          <div data-toggle="modal" data-target="#modal">
            <%= link_to_with_icon 'plus', Spree.t(:new_line_item), spree.new_admin_order_line_item_path(@order), data: { turbo_frame: :dialog_modal }, class: "btn btn-link btn-sm" %>
          </div>
        <% end %>
        <% if @order.completed? %>
          <button class="btn btn-light btn-sm text-muted" type="button" data-toggle="collapse" data-target="#line-items" aria-expanded="false" aria-controls="collapseExample">
            <%= Spree.t(:show_details) %>
            <%= icon('selector', height: 12, class: 'mr-0 ml-1') %>
          </button>
        <% end %>
      </div>
    </div>
    <div class="card-body mb-0 p-0 <% if @order.completed? && params[:line_item_updated].blank? %>collapse<% else %>show<% end %>" id="line-items">
      <div class="order-line-items">
        <div class="text-muted text-center border-bottom py-2 px-3 font-size-sm order-line-items__row">
          <span class="text-left">
            <%= Spree.t(:item_description) %>
          </span>
          <span>
            <%= Spree.t(:price) %>
          </span>
          <span>
            <%= Spree.t(:quantity) %>
          </span>
          <span>
            <%= Spree.t(:subtotal) %>
          </span>
          <span>
            <%= Spree.t(:tax) %>
          </span>
          <span>
            <%= Spree.t(:discount) %>
          </span>
          <span>
            <%= Spree.t(:total) %>
          </span>
          <span>
          </span>
        </div>
        <% if @line_items.any? %>
          <%= render collection: @line_items, partial: 'spree/admin/orders/line_item', cached: spree_base_cache_scope %>
        <% else %>
          <div class="px-3 py-3 text-center text-muted" style="grid-column: 0/-1" >
            No line items for this order yet.
          </div>
        <% end %>
      </div>
    </div>
  <% elsif can?(:create, Spree::LineItem.new(order: @order)) %>
    <div data-toggle="modal" data-target="#modal">
      <%= link_to_with_icon 'plus', Spree.t(:new_line_item), spree.new_admin_order_line_item_path(@order), data: { turbo_frame: :dialog_modal }, class: "btn btn-link w-100 py-3" %>
    </div>
  <% end %>
<% end %>

